package com.yc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yc.entity.User;
import com.yc.mapper.UserMapper;
import com.yc.service.IUserService;
import com.yc.service.ServiceException;
import org.springframework.stereotype.Service;

/**
 * <p>
 * InnoDB free: 5120 kB 服务实现类
 * </p>
 *
 * @author ly
 * @since 2022-05-08
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {
    @Override
    public User login(User user) throws ServiceException {
        LambdaQueryWrapper<User> qw = Wrappers.lambdaQuery(User.class);
        qw.eq(User::getUsername, user.getUsername())
                .eq(User::getPassword, user.getPassword());
        User user1 = getBaseMapper().selectOne(qw);
        if(user1==null){
            throw new ServiceException("用户名或密码错误");
        }
        return user1;
    }
}
